#include "modify.h"
#include "ui_modify.h"

Modify::Modify(QString i,QWidget *parent) :
    QDialog(parent),
    ui(new Ui::Modify)
{ 
    ui->setupUi(this);
    id = i;
}

Modify::~Modify()
{
    delete ui;
}

void Modify::on_pushButton_2_clicked()
{
    close();
}

void Modify::on_pushButton_clicked()
{
    QString name = ui->lineEdit->text();
    if(name == "")
    {
         QMessageBox::warning(this,"提示","请输入姓名");
         return;
    }
    QString subject = ui->comboBox->currentText();
    QString score = ui->lineEdit_2->text();
    QString sql = "UPDATE student SET name=?,subject=?,score=? WHERE id=?";
    QSqlQuery sq;
       sq.prepare(sql);
       sq.addBindValue(name);
       sq.addBindValue(subject);
       sq.addBindValue(score);
       sq.addBindValue(id);

       if(sq.exec())
       {
           QMessageBox::information(this,"通知","修改成功");
           close();
       }else
       {
           QString text = sq.lastError().text();
           qDebug() << "修改失败" << text;
       }
}
